package com.h2wallet.newsapi.modular.news.controller;

import com.h2wallet.newsapi.modular.news.service.ArticleService;
import com.h2wallet.newsapi.modular.news.vo.Article;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@Api(description="文章API")
@RestController
@RequestMapping(value = "/articles", produces = MediaType.APPLICATION_JSON_VALUE)
public class ArticleController {

    @Resource
    private ArticleService articleService;



    @ApiOperation(value = "获取文章")
    @GetMapping(value = "/{id}")
    public Article get(@PathVariable("id") int id) {
        return articleService.findOne(id);
    }

    @ApiOperation(value = "添加文章")
    @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
    public Article post(@RequestBody Article article) {
        return articleService.save(article);
    }


    @ApiOperation(value = "添加文章")
    @PutMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
    public Article put(@RequestBody Article article) {
        return articleService.save(article);
    }

}
